<template>
  <div class="right-nav">
    <el-form
      :model="form"
      label-width="80px"
      status-icon
      :rules="rules"
      ref="ruleFormRef"
      label-position="top"
    >
      <el-form-item label="商品名称" prop="goods_name">
        <el-input v-model="form.goods_name" />
      </el-form-item>
      <el-form-item label="商品价格" prop="goods_price">
        <el-input v-model="form.goods_price" />
      </el-form-item>
      <el-form-item label="商品数量" prop="goods_number">
        <el-input v-model="form.goods_number" />
      </el-form-item>
      <el-form-item label="商品重量" prop="goods_weight">
        <el-input v-model="form.goods_weight" />
      </el-form-item>
      <el-form-item
        v-if="store.state.goodsFormType.type == 1"
        label="商品分类"
        prop="goods_cat"
      >
        <el-cascader
          v-model="form.goods_cat"
          :options="catList"
          :props="props"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { inject, reactive } from "vue";
import { getCategories } from "@/api/goods";
import { useStore } from "vuex";
// 数据定义
let ruleFormRef = reactive({});
let form = inject("form1");
let catList = reactive([]);
let store = useStore();
(async () => {
  let res = await getCategories();
  catList.push(...res.data);
})();
let props = {
  expandTrigger: "hover",
  value: "cat_id",
  label: "cat_name",
};
let ls = reactive({
  goods_name: "11",
  goods_price: 0,
  goods_number: 0,
  goods_weight: 0,
});
if (store.state.goodsFormType.type == 1) {
  ls.goods_cat = reactive([]);
}
Object.assign(form, ls);
let rules = {
  goods_name: [
    { required: true, message: "请输入新建商品名称", trigger: "blur" },
    { min: 3, max: 10, message: "用户名位3~10个字", trigger: "blur" },
  ],
};

// 函数
</script>

<style lang="scss" scoped>
.right-nav {
  max-height: 600px;
  overflow: auto;
}
</style>